<script>
import EntryLabel from '@comp/warehouse/EntryLabel.vue'
import { getAction } from '@api/manage'
import InboundRecordLabelList from './InboundRecordLabelList.vue'

export default {
  name: 'InboundRecordLabelPrintModal',
  components: { InboundRecordLabelList, EntryLabel },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      model: {},
      selectedRowKeys: [],
      selectionRows: [],
      queryParam: {},
      labelList: []
    }
  },
  methods: {
    print(record) {
      if (!record || !record.inboundRecordItemId) {
        return
      }
      this.model = Object.assign({}, record)
      this.queryParam.inboundRecordItemId = record.inboundRecordItemId
      this.queryParam.batchNumber = record.batchNumber
      this.fetchData()
      this.visible = true
    },
    fetchData() {
      getAction('/wms/inbound/inbound-label/list', this.queryParam)
        .then(({ result }) => {
          if (result) {
            this.labelList = result
          }
        })
    },
    handleOk() {
      if (!this.selectionRows || this.selectionRows.length <= 0) {
        this.$message.error('请选择要打印的批次')
        return
      }
      const ids = this.selectionRows.map((item) => item.id).join('\',\'')
      window.open(`${window._CONFIG['domianURL']}/jmreport/view/1099651769747447808?id=${ids}`, '_blank')
      this.$emit('ok')
      this.close()
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.labelList = []
      this.$emit('close')
      this.visible = false
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
    }
  }
}
</script>

<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    fullscreen
    okText="打印"
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    cancelText="关闭"
    @cancel="handleCancel">
    <inbound-record-label-list :data-source="labelList" @change="onSelectChange" />
  </j-modal>
</template>

<style scoped>

</style>